package cn.tedu.charging.user.controller;

import cn.tedu.charging.common.pojo.param.ChargeParam;
import cn.tedu.charging.common.pojo.param.VehicleBindParam;
import cn.tedu.charging.common.pojo.vo.BalanceVO;
import cn.tedu.charging.common.pojo.vo.VehicleVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    //微信登录 入参 String code String nickname
    @GetMapping("/user/wx/login")
    public JsonResult<Integer> wxLogin(String code,String nickName){
        //调用service层
        Integer userId=userService.wxLogin(code,nickName);
        return JsonResult.ok(userId);
    }

    @GetMapping("/user/vehicle/binded/{userId}")
    public JsonResult<VehicleVO> bindedVehicle(@PathVariable("userId") Integer userId){
        //控制层要什么返回 业务层就给什么 业务层从数据层获取的是entity po cache需要转化
        VehicleVO vo=userService.bindedVehicle(userId);
        return JsonResult.ok(vo);
    }
    //给登录用户绑定车辆
    @PostMapping("/user/vehicle/bind")
    public JsonResult<Integer> bindVehicle(@RequestBody VehicleBindParam param){
        Integer vehicleId=userService.bindVehicle(param);
        return JsonResult.ok(vehicleId);
    }
    //给登录用户解绑车辆
    @GetMapping("/user/vehicle/unbind")
    public JsonResult unbindVehicle(Integer userId){
        userService.unbindVehicle(userId);
        return JsonResult.ok(null);
    }

    @GetMapping("/user/balance/{userId}")
    public JsonResult<BalanceVO> balance(@PathVariable("userId") Integer userId){
        BalanceVO vo=userService.balance(userId);
        return JsonResult.ok(vo);
    }
    @PostMapping("/user/charge")
    public JsonResult charge(@RequestBody ChargeParam param){
        userService.charge(param);
        return JsonResult.ok(null);
    }
}












